#include "cellspace.h"

using namespace std;

CellSpace::CellSpace(float max, int step) : maxValue(max), step(step)
{
	ships = (map<sf::Uint32, GameObject*>*)malloc(sizeof(map<sf::Uint32, GameObject*>*)*step*step);
	planets = (map<sf::Uint32, GameObject*>*)malloc(sizeof(map<sf::Uint32, GameObject*>*)*step*step);
	bullets = (map<sf::Uint32, GameObject*>*)malloc(sizeof(map<sf::Uint32, GameObject*>*)*step*step);
	int sq = step*step;
	for (int i=0;i<sq;++i)
	{
		map<sf::Uint32, GameObject*>* t = new map<sf::Uint32, GameObject*>();
		ships[i] = *t;

		t = new map<sf::Uint32, GameObject*>();
		planets[i] = *t;

		t = new map<sf::Uint32, GameObject*>();
		bullets[i] = *t;
	}
}


CellSpace::~CellSpace()
{
	int sq = step*step;
	for (int i=0;i<sq;++i)
	{
		delete &ships[i];
		delete &planets[i];
		delete &bullets[i];
	}


	free(ships);
	free(planets);
	free(bullets);
}
